package cn.test;

import java.io.IOException;

import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

public class SendMsg_webchinese {

	public static void main(String[] args) throws HttpException, IOException {
		HttpClient client = new HttpClient();
		//此处两种格式http://gbk.sms.webchinese.cn   http://utf8.sms.webchinese.cn
		PostMethod post = new PostMethod("http://utf8.sms.webchinese.cn");
		post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");//在头文件中设置转码
		NameValuePair[] data ={new NameValuePair("Uid","huwenheng"),new NameValuePair("Key","4255fbb48cc039ba5f0a"),new NameValuePair("smsMob","18678105461,13723288337"),new NameValuePair("smsText","明天早上见")};
		post.setRequestBody(data);
		
		client.executeMethod(post);
		Header[] headers = post.getRequestHeaders();//获取请求头
		int statusCode = post.getStatusCode();//状态码
		System.out.println("statusCode:"+statusCode);
		for(Header h : headers){
			System.out.println(h.toString());
		}
		String result = new String(post.getResponseBodyAsString().getBytes("utf-8"));
		System.out.println("result:"+result);
		post.releaseConnection();//断开连接
	}
}
